package com.ikas.ai.framework.statistics.function;

import com.ikas.ai.framework.statistics.StatisticType;

import java.util.List;
import java.util.Objects;

/**
 * @Description: 非空比例
 * @Author: qi.yilai
 * @Date: 2023/10/27 18:10
 * @Version: 1.0.0
 **/
public class NotNullRatioCalcFunction implements CalcFunction<List, Long, Long, Float> {

    @Override
    public Float calculate(List list) {
        float size = list.size();
        long nonNullSize = list.stream().filter(Objects::nonNull).count();
        return nonNullSize / size;
    }

    @Override
    public Float calculate(List list, Long size, Long notNullSize) {
        return (float)notNullSize/ size;
    }

    @Override
    public StatisticType type() {
        return StatisticType.NOT_NULL_RATIO;
    }
}
